
var user;
var serviceURLS = {{serviceURLS}};

function fbFinishedInit()
{
    FB.api('/me',{fields: "id,name,picture"}, function(response) {
        user ={type:'facebook',name:response.name,id:response.id,picUrl:response.picture};
        registerUser();
        document.getElementById('username').innerText = response.name;
    }
    );

}

function addHiddenInput() {
  fbLander = document.getElementById('fbLander');
  fbDiv = document.createElement('div');
  fbDiv.setAttribute('id','fbDiv');
  server = document.createElement('fb:serverfbml');
  server.setAttribute('style','width: 650px;');
  fbScript = document.createElement('script');
  fbScript.setAttribute('type','text/fbml');
  scriptText = '<fb:fbml><fb:request-form method="POST" action="http://1-test.thejettube.appspot.com/registernewstation" content="Your friend wants you to join their station on The JetTube" type="The JetTube" invite="false">    <label>Station Name: </label><input name="stationName" type="text" id="stationName"></input>  <p>  <label>Type: </label>  <input name ="public" type="radio" value="0">Private</input>  <input name ="public" type="radio" value="1" checked >Public</input>  <input name="owner" type="hidden" value="' + user.key + '"></input> <p> <label>Invite Facebook friends to join your station: </label><div class="clearfix" style="padding-bottom: 10px;">  <fb:multi-friend-selector condensed="true" style="width:80%;" />  </div>  <fb:request-form-submit />  </fb:request-form></fb:fbml>';
  scriptNode = document.createTextNode(scriptText);
  fbScript.appendChild(scriptNode);
  server.appendChild(fbScript);
  fbDiv.appendChild(server);
  fbLander.appendChild(fbDiv);
  FB.XFBML.parse();
}

function registerUser() {
    $.ajax({
        url: serviceURLS.registeruser,
        data: user,
        success: function(data) {
            updateUser(data);
        },
        dataType: 'html'});
}

function updateUser(data) {
  user.key = data;
  addHiddenInput();
}

function createUserStation()
{
  var sName = document.getElementById('stationName').value
  var isPrivate = document.getElementById('nsForm')[1].checked;
  var fbIds = getFBIdsFromInvite();
}

function getFBIdsFromInvite()
{
  
}

function login()
{
  return;
}
